package mianThread

import xxdsqljobDB.UpLoadFile
import xxdsqljobDB.XxdsqljobUtil

/**
 * Created by Administrator on 2019-07-02.
 */
class MyThread   implements Runnable {
    long threadId
    public MyThread( long threadId){
        this.threadId =   threadId
    }
    @Override
    void run() {
        if(threadId){
            try {
                println("${new Date().format("yyyy-MM-dd HH:mm:ss")} job:${threadId} 开始执行!")
                XxdsqljobUtil.updateJobCfgRUN(threadId,new Date())
                //*********处理业务逻辑****************
                //查询sql
                List<UpLoadFile> upLoadFile = XxsqlJobThread.startDownLoad(threadId)
                XxdsqljobUtil.sendEmail(threadId,upLoadFile)
                XxdsqljobUtil.updateJobCfgNORMAL(threadId,new Date())
            }catch (Exception e){
                def errorMsg = e.getMessage()
                XxdsqljobUtil.updateJobCfgERROR(threadId,errorMsg.length()>500? errorMsg.substring(0,500) : errorMsg)
                e.printStackTrace()
            }finally{
                XxdsqljobUtil.insertJobHis(threadId)
            }
        }else{
            println "Job不存在.........."
        }
    }
}
